import Core from '@/core.js'
export default {
  data() {
    return {
      Core,
      localStorage: '',
      checked: true,
      urlList: [
        '/pages_common/pages_me/safeCenter/safeCenter',
        '/pages_login/userAgreement/userAgreement?type=0',
        '/pages_login/userAgreement/userAgreement?type=1',
        '/pages_common/pages_me/aboutUs/aboutUs',
        '/pages_common/pages_me/feedback/feedback',
      ],
    }
  },
  onLoad() {
    // #ifdef APP-PLUS
    this.computedCache()
    // #endif
  },
  methods: {
    change(e) {
      //打开true 关闭false
    },

    // 计算缓存
    computedCache() {
      plus.cache.calculate((size) => {
        console.log(size)
        let cacheSize = size / 1024 / 1024
        this.localStorage = cacheSize.toFixed(2) + 'MB'
      })
    },

    // 清除缓存
    clearCache() {
      uni.showModal({
        content: '确定清除缓存吗？',
        confirmColor: '#FBB000',
        success: (res) => {
          if (res.confirm) {
            plus.cache.clear(() => {
              uni.showToast({
                title: '清除成功',
                icon: 'none',
                success: () => {
                  this.computedCache()
                },
              })
            })
          }
        },
      })
    },

    // 跳转页面
    goPage(index) {
      uni.navigateTo({
        url: this.urlList[index],
      })
    },

    //退出登录
    logout() {
      this.$store.commit('resetInfo')
      this.$store.commit('user/resetInfo')
      let promise = this.tim.logout()
      promise
        .then((res) => {
          this.$store.commit('news/reset')
        })
        .catch((err) => {
          console.log('退出失败')
        })
      uni.removeStorageSync('token')
      uni.removeStorageSync('userInfoDetail')
      uni.removeStorage({
        key: 'Ztc_B_USER_INFO',
        success: function (res) {
          uni.redirectTo({
            url: '/pages_login/login/login',
          })
        },
      })
    },
  },
}
